using System;
using System.Collections.Generic;
using System.Text;
using Musicman.Entities;

namespace Musicman.Entities.BusinessEntities
{
    public class SearchLocationCollection : IEnumerable<Searchlocation>, ICollection<Searchlocation>
    {
        private List<Searchlocation> _innerList = new List<Searchlocation>();
        public Dictionary<String, Searchlocation> _innerDictionary = new Dictionary<string, Searchlocation>();

        public List<Searchlocation> InnerList
        {
            get { return _innerList; }
            set { _innerList = value; }
        }

        #region IEnumerable<Searchlocation> Members

        public IEnumerator<Searchlocation> GetEnumerator()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region ICollection<Searchlocation> Members

        public void Add(Searchlocation item)
        {
            if (!Contains(item))
            {
                string key = item.Name.ToLower();
                this._innerList.Add(item);
                this._innerDictionary.Add(key, item);
            }
        }

        public void Clear()
        {
            this._innerList.Clear();
            this._innerDictionary.Clear();
        }

        public bool Contains(Searchlocation item)
        {
            string key = item.Name.ToLower();
            return _innerDictionary.ContainsKey(key);
        }

        public void CopyTo(Searchlocation[] array, int arrayIndex)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public int Count
        {
            get { return _innerList.Count; }
        }

        public bool IsReadOnly
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public bool Remove(Searchlocation item)
        {
            string key = item.Name.ToLower();
            if (_innerDictionary.ContainsKey(key))
            {
                Searchlocation location = _innerDictionary[key];
                _innerList.Remove(location);
                _innerDictionary.Remove(key);
                return true;
            }
            return false;

        }

        #endregion


        public Searchlocation this[int index]
        {
            get
            {
                return _innerList[index];
            }
        }

        public Searchlocation this[string key]
        {
            get
            {
                return _innerDictionary[key.ToLower()];
            }
        }

    }
}
